<!DOCTYPE html>
<html>
<head>
    <title>红米6A立即购买—小米商城</title>
    <meta charset="utf-8">
    <link rel="shortcut icon" type="image/x-icon" href="/images/favicon/favicon.ico"/>
    <link rel="stylesheet" href="/css/General style.css">
    <link rel="stylesheet" href="/css/header.css">
    <link rel="stylesheet" href="/css/iconfont.css">
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/css/mi.css">
    <link rel="stylesheet" type="text/css" href="/css/shop.css">
    <link rel="stylesheet" type="text/css" href="/css/footer1.css">
    <link rel="stylesheet" href="/css/login.css">
    <link rel="stylesheet" type="text/css" href="/font-awesome/css/font-awesome.min.css">

</head>
<body>
<div th:replace="header::top"></div>
<!--   主体内容上半部分   -->
<div class="content-top">
    <div class="detail">
        <div class="content">
            <div class="detail_left">
                <b>小米8</b><span></span><a href="#">小米8 SE</a>
            </div>
            <div class="detail_right">
                <a href="">概述</a><span></span>
                <a href="">图集</a><span></span>
                <a href="">参数</a><span></span>
                <a href="">F码通道</a><span></span>
                <a href="">用户评价</a>
            </div>
        </div>
    </div>

    <div class="shop_detail">
        <div class="shop_detail_pic">
            <div class="layui-carousel" id="test1" lay-filter="test1">
                <div carousel-item="">
                    <div><img id="mainImage" src="/static/img/lun/1.jpg"></div>
                    <div><img src="/static/img/lun/2.jpg"></div>
                    <div><img src="/static/img/lun/3.jpg"></div>
                    <div><img src="/static/img/lun/4.jpg"></div>
                </div>
            </div>
        </div>
        <div class="shop_detail_menu">
            <h1 id="name"></h1>
            <p id="subtitle">12nm高性能处理器 / 5.45" 小巧全面屏 / 1300万高清相机 / “小杨柳腰”机身</p>
            <h2 id="price">599</h2>
            <div class="detail_map">
                <i class="fa fa-map-marker " style="color:#ccc;font-size: 15px;"></i>
                <span>北京  &nbsp;北京市   &nbsp;东城区   &nbsp;永定门外街道  <a href="" style="color:#FF6A00;">  &nbsp;修改 </a> </span><br>
                <span style="color:#FF6A00;margin-left: 12px;">有现货</span>
            </div>
            <div class="shop_detail_much">
                <p>选择版本</p>
                <div class="detail_much_left">4GB+64GB 全网通 <span data-val="599">599元</span></div>
                <div class="detail_much_left">6GB+64GB 全网通 <span data-val="699">699元</span></div>

            </div>
            <div class="clear"></div>
            <div class="shop_detail_color">
                <p>选择颜色</p>
                <div class="detail_color_left detail_color_left_checked"><span style="background:#F6E6D8; "></span> 金色
                </div>
                <div class="detail_color_left"><span style="background:#3C3F43;"></span> 深灰</div>
                <div class="detail_color_left"><span style="background:#D93239;"></span> 亮红</div>
                <div class="detail_color_left"><span style="background:#3871B7;"></span> 亮蓝</div>
            </div>
            <div class="clear"></div>
            <div class="shop_detail_bz">
                <div class="shop_detail_bz0">
                    <p>选择小米提供的保障服务</p>
                    <a href="#">了解保障服务 ></a>
                    <div class="clear"></div>
                </div>
                <div class="shop_detail_bz1" style="border-bottom: none">
                    <span class="fa fa-check-circle shop_detail_button"></span>
                    <img src="/static/img/bz.jpg">
                    <div class="shop_detail_1">
                        <p style="font-size: 18px;color: #333;">意外保障服务</p>
                        <p>手机意外摔落/进水/碾压等损坏</p>
                        <b class="fa fa-check-square shop_detail_button"></b> &nbsp;我已阅读&nbsp; <a> &nbsp;服务条款&nbsp; </a>|<a>
                        &nbsp;服务条款&nbsp;</a>
                        <span data-val="99">99元</span>
                    </div>
                </div>
                <div class="shop_detail_bz1">
                    <span class="fa fa-check-circle shop_detail_button"></span>
                    <img src="/static/img/bz.jpg">
                    <div class="shop_detail_1">
                        <p style="font-size: 18px;color: #333;">碎屏保障服务</p>
                        <p>手机意外碎屏</p>
                        <b class="fa fa-check-square shop_detail_button"></b> &nbsp;我已阅读&nbsp; <a> &nbsp;服务条款&nbsp; </a>|<a>
                        &nbsp;服务条款&nbsp;</a>
                        <span data-val="179">179元</span>
                    </div>
                </div>
            </div>
            <div class="shop_detail_zj">
                <div>
                    <p>小米8 6GB+64GB 黑色</p><span id="phonePrice">699元</span>
                    <div class="clear"></div>
                </div>
                <p id="totalPrice" style="color:#FF6A00;font-size: 25px;margin-left: 30px;">总计&nbsp;：&nbsp;699元</p>
            </div>
            <div id="addCart" class="shop_detail_cart">加入购物车</div>
            <p><i class="fa fa-check-circle-o"></i> 7天无理由退货 <i class="fa fa-check-circle-o"></i> 15天质量问题换货
                <i class="fa fa-check-circle-o"></i> 365天保修 </p>
        </div>
        <div class="clear"></div>
    </div>
    <div class="detail_content">
        <div class="detail_content_1">
            <p>特别说明</p>
            <div id="detail"></div>
            <img src="/static/img/sm.jpg">
            <p>官方微信</p>
            <img src="/static/img/2.jpg">
        </div>
    </div>
    <!--   网页底部   -->
    <div class="footer-top">
        <div class="footer-top_li">
            <div class="footer-top_li_1">
                <a href="#"><i class="fa fa-wrench"></i>预约维修服务</a><span></span>
                <a href="#"><i class="fa fa-rotate-right "></i>7天无理由退货</a><span></span>
                <a href="#"><i class="fa fa-refresh"></i>15天免费换货</a><span></span>
                <a href="#"><i class="fa fa-gift"></i>满150元包邮</a><span></span>
                <a href="#"><i class="fa fa-map-marker"></i>520余家售后网点</a>
            </div>
            <span class="separate"></span>
            <div class="footer-top_li_2">
                <div class="footer-top_li_a">
                    <dl>
                        <dt>帮助中心</dt>
                        <dd><a href="">账户管理</a></dd>
                        <dd><a href="">购物指南</a></dd>
                        <dd><a href="">订单操作</a></dd>
                    </dl>
                    <dl>
                        <dt>服务支持</dt>
                        <dd><a href="">售后政策</a></dd>
                        <dd><a href="">自助服务</a></dd>
                        <dd><a href="">相关下载</a></dd>
                    </dl>
                    <dl>
                        <dt>线下门店</dt>
                        <dd><a href="">小米之家</a></dd>
                        <dd><a href="">服务网点</a></dd>
                        <dd><a href="">授权体验店</a></dd>
                    </dl>
                    <dl>
                        <dt>关于小米</dt>
                        <dd><a href="">了解小米</a></dd>
                        <dd><a href="">加入小米</a></dd>
                        <dd><a href="">投资者关系</a></dd>
                    </dl>
                    <dl>
                        <dt>关注我们</dt>
                        <dd><a href="">新浪微博</a></dd>
                        <dd><a href="">官网微博</a></dd>
                        <dd><a href="">联系我们</a></dd>
                    </dl>
                    <dl>
                        <dt>特色服务</dt>
                        <dd><a href="">F码通道</a></dd>
                        <dd><a href="">礼物码</a></dd>
                        <dd><a href="">防伪查询</a></dd>
                    </dl>
                    <div class="connect">
                        <p class="telephone">Feir-520-1314</p>
                        <p class="time">周一至周日 8:00-18:00<br>(仅收市话费)</p>
                        <button><span class="fa fa-commenting "></span> 联系客服</button>
                    </div>
                </div>
                <div class="footer-top_li_b"></div>
            </div>
        </div>

    </div>
    <div class="footer-bottom">
        <div class="footer-bottom_li">
            <div class="footer-bottom_li_1">
                <img src="/static/img/footlogo.png" alt="" class="logoBottom">
            </div>
            <div class="footer-bottom_li_2">
                <div class="footer-bottom_li_a">
                    <ul>
                        <li>小米商城<span></span></li>
                        <li>MIUI<span></span></li>
                        <li>米家<span></span></li>
                        <li>米聊<span></span></li>
                        <li>多看<span></span></li>
                        <li>游戏<span></span></li>
                        <li>路由器<span></span></li>
                        <li>米粉卡<span></span></li>
                        <li>政企服务<span></span></li>
                        <li>小米天猫店<span></span></li>
                        <li>隐私政策<span></span></li>
                        <li>问题反馈<span></span></li>
                        <li>Select Region</li>
                    </ul>
                </div>
                <div class="footer-bottom_li_b">
                    <a href="">©mi.com</a>
                    京ICP证110507号
                    <a href="">京ICP备10046444号</a>
                    <a href="">京公网安备11010802020134号</a>
                    <a href="">京网文[2014]0059-0009号</a>
                    <br>
                    违法和不良信息举报电话：185-0130-1238，本网站所列数据，除特殊说明，所有数据均出自我司实验室测试
                </div>
            </div>
            <div class="footer-bottom_li_3">
                <img src="/static/img/footericon1.png" alt="" class="icon">
                <img src="/static/img/footericon2.png" alt="" class="icon">
                <img src="/static/img/footericon3.png" alt="" class="icon">
                <img src="/static/img/footericon4.png" alt="" class="icon">
                <img src="/static/img/footericon5.png" alt="" class="icon">
            </div>
            <div class="footer-bottom_li_4">
                探索黑科技，小米为发烧而生！
            </div>
        </div>
    </div>
</div>

<form class="layui-form" action="">
    <div id="loginFrom" class="login_card" style="display: none">
        <img src="./images/two.png" class="two">
        <h2 class="title">登录</h2>
        <!-- 账号 -->
        <div class="user_box">
            <div class="user">
                <input type="text"  id="u" name="name" class="username">
                <label for="u">邮箱/手机号码/小米ID</label>
            </div>
            <div class="user_msg">请输入账号</div>
        </div>
        <!-- 密码 -->
        <div class="user_box">
            <div class="user">
                <input type="password" id="u" name="password" class="password">
                <label for="u">密码</label>
            </div>
            <div class="user_msg">请输入密码</div>
        </div>
        <!-- 登录按钮 -->
        <button class="login_btn" lay-submit lay-filter="submit">登录</button>
        <!-- 登录说明 -->
        <div class="login_other">
            <a href="#" class="l_l">忘记密码？</a>
            <a href="#" class="l_right">手机号登录</a>
        </div>
    </div>
</form>
<script src="/jquery-2.1.4.js"></script>
<script src="/layui/layui.js"></script>
<script src="/mylayer.js"></script>
<script src="/js/index.js"></script>
<script src="/js/detail.js"></script>
<script th:inline="javascript">
    layui.use(['carousel','form'], function () {
        var carousel = layui.carousel;
        var form = layui.form;
        //建造实例
        carousel.render({
            elem: '#test1'
            , width: '560px' //设置容器宽度
            , height: '560px'
            , arrow: 'always' //始终显示箭头
            //,anim: 'updown' //切换动画方式
        });


        var queryString = window.location.search;
        var urlParams = new URLSearchParams(queryString);
        var id = urlParams.get("id");

        $.post(
            '/product/selectById',
            {'id': id},
            function (result) {
                console.log(result);
                if (result.code == 0) {
                    $('#name').text(result.data.name);
                    $('#subtitle').text(result.data.subtitle);
                    $('#price').text(result.data.price);
                    $('#detail').html(result.data.detail);
                    $('#mainImage').attr('src', '/pic/' + result.data.mainImage);
                }
            },
            'json'
        );
        
        $('#addCart').click(function () {
            //加入购物车之前首先判断有没有登录
            //如果没有登录首先完成登录
            //如果已经登录，就将商品信息插入到cart购物车表里面，然后跳转到购物车列表界面
            /*var user = [[${session.user}]];
            if (user) {
                addToCart();
            } else {
                //没有登录，弹出登录界面
                layer.open({
                    type: 1,
                    title: '登录',
                    area: ['480px', '380px'],
                    content: $('#loginFrom')
                });
            }*/
            /*$.post(
                '/user/checkUserLogin',
                function (result) {
                    if (result.code == 0) {
                        //代表已经登录，直接插入购物车
                        addToCart();
                    } else {
                        //没有登录，弹出登录界面
                        layer.open({
                            type: 1,
                            title: '登录',
                            area: ['480px', '380px'],
                            content: $('#loginFrom')
                        });
                    }
                },
                'json'
            );*/
            addToCart();
        });

        // 绑定提交事件
        form.on('submit(submit)', function (data) {
            var field = data.field; // 获取表单字段值
            console.log(data);
            $.post(
                '/user/login',
                field,
                function (result) {
                    if (result.code == 0) {
                        //mylayer.okUrl(result.msg, '/page/cart/list');
                        addToCart();
                    } else {
                        mylayer.errorMsg(result.msg);
                    }
                },
                'json'
            );
            return false; // 阻止默认 form 跳转
        });

        //这里给所有ajax请求添加一个complete函数
        /*$(document).ajaxComplete( function(event, jqXHR, options){
            //拦截器实现超时跳转到登录页面
            // 通过xhr取得响应头
            var REDIRECT = jqXHR.getResponseHeader("REDIRECT");
            //如果响应头中包含 REDIRECT 则说明是拦截器返回的需要重定向的请求
            if (REDIRECT == "REDIRECT") {
                var win = window;
                while (win != win.top) {
                    win = win.top;
                }
                win.location.href = jqXHR.getResponseHeader("CONTEXTPATH");
            }
        } );*/

        function addToCart() {
            console.log('addToCart');
            /*$.post(
                '/cart/add?returnUri=/page/product/detail?id='+id,
                {'productId': id},
                function (result) {
                    if (result.code == 0) {
                        mylayer.okUrl(result.msg, '/page/cart/list');
                    } else {
                        mylayer.errorMsg(result.msg);
                    }
                },
                'json'
            );*/

            $.ajax({
                url: '/cart/add?returnUri=/page/product/detail?id='+id,
                type: 'POST',
                data: {'productId': id},
                dataType: 'json',
                success: function (result) {
                    if (result.code == 0) {
                        mylayer.okUrl(result.msg, '/page/cart/list');
                    } else {
                        mylayer.errorMsg(result.msg);
                    }
                },
                complete : function(xhr, status) {
                    //拦截器实现超时跳转到登录页面
                    // 通过xhr取得响应头
                    var REDIRECT = xhr.getResponseHeader("REDIRECT");
                    //如果响应头中包含 REDIRECT 则说明是拦截器返回的需要重定向的请求
                    if (REDIRECT == "REDIRECT") {
                        var win = window;
                        while (win != win.top) {
                            win = win.top;
                        }
                        win.location.href = xhr.getResponseHeader("CONTEXTPATH");
                    }
                }
            });
        }

    });
</script>
</body>
</html>